import Vue from 'vue'
import VueRouter from 'vue-router'
import demo from '@/common/router.js'
import main from '@/router/main.js'

const router = new VueRouter({
  // mode: 'history',
  // base: '/', //history需要设置
  routes: [
    {
      path: '/',
      redirect: '/demo',
    },
    //测试页面
    ...demo,
    //逻辑首页
    ...main,
    //未知页面
    {
      path: '*',
      name: 'limit',
      component: () => import(/* webpackChunkName: "limit" */ '@/common/page/404.vue'),
    },
  ],
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(error => error)
}
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function (location) {
  return originalReplace.call(this, location).catch(error => error)
}
Vue.use(VueRouter)

export default router
